package org.itstack.demo.netty.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.itstack.demo.netty.codec.ObjDecoder;
import org.itstack.demo.netty.codec.ObjEncoder;
import org.itstack.demo.netty.domain.TransportProtocol;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Resource
    private MyServerHandler myServerHandler;

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast(new ObjEncoder(TransportProtocol.class));

        socketChannel.pipeline().addLast(new ObjDecoder(TransportProtocol.class));

        socketChannel.pipeline().addLast(myServerHandler);
    }
}
